package com.itheima.collectionDemo;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;

public class CollectionDemo3 {
    public static void main(String[] args) {
        Collection<String> list = new ArrayList<>();
        list.add("a");
        list.add("b");
        list.add("c");
        list.add("d");
        list.add("e");

        // 创建迭代器对象，默认指向集合的0索引处
        Iterator<String> it = list.iterator();
        // 遍历迭代器
        // 判定当前位置是否有元素可取出
        System.out.println(it.hasNext());
        // 取出当前位置的元素 + 将迭代器移动到下一个索引处
        System.out.println(it.next());
        System.out.println(it.next());
        System.out.println(it.next());
        System.out.println(it.next());
        System.out.println(it.next());
//        System.out.println(it.next());

        while (it.hasNext()) {
            System.out.println(it.next());
        }
    }
}
